More Info: Passing and Returning Values


Let's step through how a function returns and is passed variables.

The first word in the function header is void. This tells us that the function is going to be returning just that, void. As its name implies, void is a special data type that means for our purposes "nothing". When your function doesn't return anything, you put this to say so.

The second word in the function header is hello_world. This is what we're naming the function. Be careful, C++ is case sensitive! If you try to call this function as HELLO_WORLD or Hello_World, it wouldn't work.

The third part in the function header, surrounded by parentheses, is int foo. This is saying that we are going to pass an intfoo inside our function. From now on in this function we're creating, whenever we use the variable name foo, we'll be using the argument that was passed to the function. For instance, if this function hello_world was called like:

hello_world(311);

Inside the function, when we used the foo, it would have the value 311.


Table of Contents